﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal
{
    public partial class Abstract : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["rus"] != null)
            {
                DB.Item.ItemJournal journal = new DB.DbPublications().GetJournalOfPublication(Request.Params["rus"].ToString());
                NavigationLabel.Text = String.Format("<a href=\"Journals.aspx\">Номера журналов</a>/<a href=\"Journals.aspx?id={0}\">№ {1} за {2} год</a>", journal.Id, journal.Number, journal.Year);
                DB.Item.ItemPublication publication = new DB.DbPublications().GetPublicationById(Request.Params["rus"].ToString());
                string html = String.Format("<table style=\"font-size: 20px\"><tbody><tr><td><b>{0}</b></td></tr><tr><td>{1}<td></tr><tr><td><a href=\"\">Abstract</a>|<a href=\"\">PDF</a></td></tr>", publication.TitleRussian, new DB.DbPublications().GetPublicationAuthors(publication.Id));
                html += String.Format("<tr><td><p style=\"white-space: pre-wrap\"><b>Резюме</b>:<br>{0}</p></td></tr><tr><td><b>Ключевые слова:</b><p style=\"white-space: pre-wrap\">{1}</p></td></tr></tbody></table>", publication.SummaryRussian, publication.KeywordsRussian);
                ContentLabel.Text = html;
            }
            else if (Request.Params["eng"] != null)
            {

                DB.Item.ItemJournal journal = new DB.DbPublications().GetJournalOfPublication(Request.Params["eng"].ToString());
                NavigationLabel.Text = String.Format("<a href=\"Journals.aspx\">Номера журналов</a>/<a href=\"Journals.aspx?id={0}\">№ {1} за {2} год</a>", journal.Id, journal.Number, journal.Year);
                DB.Item.ItemPublication publication = new DB.DbPublications().GetPublicationById(Request.Params["eng"].ToString());
                string html = String.Format("<table style=\"font-size: 20px\"><tbody><tr><td><b>{0}</b></td></tr><tr><td>{1}<td></tr><tr><td><a href=\"\">Резюме</a>|<a href=\"\">PDF</a></td></tr>", publication.TitleEnglish, new DB.DbPublications().GetPublicationAuthors(publication.Id));
                html += String.Format("<tr><td><p style=\"white-space: pre-wrap\"><b>Abstract</b>:<br>{0}</p></td></tr><tr><td><b>Keywords:</b><p style=\"white-space: pre-wrap\">{1}</p></td></tr></tbody></table>", publication.SummaryEnglish, publication.KeywordsEnglish);
                ContentLabel.Text = html;
            }
            else if (Request.Params["file"] != null)
            {

                DB.Item.ItemJournal journal = new DB.DbPublications().GetJournalOfPublication(Request.Params["file"].ToString());
                DB.Item.ItemPublication item = new DB.DbPublications().GetPublicationById(Request.Params["file"].ToString());
                HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STEAM";
                string Header = "Attachment; Filename=" + item.FileArticle;
                HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
                System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("\\Account\\files\\publications\\") + item.FileArticle);
                HttpContext.Current.Response.WriteFile(file.FullName);
                HttpContext.Current.Response.End();
                Response.Redirect(String.Format("Journals.aspx?id={0}", journal.Id));
            }
        }
    }
}